home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / include / afx.h next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  58.4 KB  |  1,989 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #ifndef __AFX_H__
  12. #define __AFX_H__
  13.  
  14. #ifndef __cplusplus
  15.     #error MFC requires C++ compilation (use a .cpp suffix)
  16. #endif
  17.  
  18. #if defined(_WIN32_WCE)
  19.     #include <wce.h>
  20.     #define WCE_DEL /##/
  21.     #define WCE_INS
  22.     #define WCE_FCTN(fctn) wce_##fctn
  23.     #define WCE_IF(wce,base) wce
  24. #else // _WIN32_WCE
  25.     #define WCE_DEL
  26.     #define WCE_INS /##/
  27.     #define WCE_FCTN(fctn) fctn
  28.     #define WCE_IF(wce,base) base
  29. #endif // _WIN32_WCE
  30. /////////////////////////////////////////////////////////////////////////////
  31.  
  32. #ifdef _AFX_MINREBUILD
  33. #pragma component(minrebuild, off)
  34. #endif
  35. #ifndef _AFX_FULLTYPEINFO
  36. #pragma component(mintypeinfo, on)
  37. #endif
  38.  
  39. #include <afxver_.h>        // Target version control
  40.  
  41. #ifndef _AFX_NOFORCE_LIBS
  42.  
  43. #if defined(_WIN32_WCE)
  44. /////////////////////////////////////////////////////////////////////////////
  45. // WinCE libraries
  46.  
  47. // Specify MFC libraries
  48. #ifndef _AFXDLL
  49.     #ifdef _DEBUG
  50.         #pragma comment(lib, "uafxwced.lib")
  51.     #else
  52.         #pragma comment(lib, "uafxwce.lib")
  53.     #endif
  54. #else      
  55.     #ifdef _DEBUG
  56.         #pragma comment(lib, "mfcs42d.lib")
  57.         #pragma comment(lib, WCE_MFC_FILENAME(d.lib))
  58.     #else
  59.         #pragma comment(lib, "mfcs42.lib")
  60.         #pragma comment(lib, WCE_MFC_FILENAME(.lib))
  61.     #endif
  62. #endif
  63.  
  64. // Specify OS libraries
  65. #pragma comment(lib, "coredll.lib")
  66. #pragma comment(lib, "commctrl.lib")
  67. #if !defined(_WIN32_WCE_PSPC)
  68.     #pragma comment(lib, WCE_COMMDLG_LIB)
  69. #endif // _WIN32_WCE_PSPC
  70.  
  71. // Specify CRT library (and unspecify CRT's marked by /MT flag)
  72. #if (_WIN32_WCE >= 201)
  73.     #pragma comment(lib, "corelibc.lib")
  74.     #pragma comment(linker, "/nodefaultlib:libc.lib")
  75.     #pragma comment(linker, "/nodefaultlib:libcd.lib")
  76.     #pragma comment(linker, "/nodefaultlib:libcmt.lib")
  77.     #pragma comment(linker, "/nodefaultlib:libcmtd.lib")
  78.     #pragma comment(linker, "/nodefaultlib:oldnames.lib")
  79. #else // _WIN32_WCE >= 201
  80. #if defined(_DEBUG)
  81.     #pragma comment(lib, "libcmtd.lib")
  82.     #pragma comment(linker, "/nodefaultlib:corelibc.lib")
  83. #else
  84.     #pragma comment(lib, "libcmt.lib")
  85.     #pragma comment(linker, "/nodefaultlib:corelibc.lib")
  86. #endif
  87. #endif // _WIN32_WCE >= 201
  88.  
  89. #pragma comment(linker, "/ignore:4089")
  90.  
  91. #else  // _WIN32_WCE
  92. /////////////////////////////////////////////////////////////////////////////
  93. // Win32 libraries
  94.  
  95. #ifndef _AFXDLL
  96.     #ifndef _UNICODE
  97.         #ifdef _DEBUG
  98.             #pragma comment(lib, "nafxcwd.lib")
  99.         #else
  100.             #pragma comment(lib, "nafxcw.lib")
  101.         #endif
  102.     #else
  103.         #ifdef _DEBUG
  104.             #pragma comment(lib, "uafxcwd.lib")
  105.         #else
  106.             #pragma comment(lib, "uafxcw.lib")
  107.         #endif
  108.     #endif
  109. #else
  110.     #ifndef _UNICODE
  111.         #ifdef _DEBUG
  112.             #pragma comment(lib, "mfc42d.lib")
  113.             #pragma comment(lib, "mfcs42d.lib")
  114.         #else
  115.             #pragma comment(lib, "mfc42.lib")
  116.             #pragma comment(lib, "mfcs42.lib")
  117.         #endif
  118.     #else
  119.         #ifdef _DEBUG
  120.             #pragma comment(lib, "mfc42ud.lib")
  121.             #pragma comment(lib, "mfcs42ud.lib")
  122.         #else
  123.             #pragma comment(lib, "mfc42u.lib")
  124.             #pragma comment(lib, "mfcs42u.lib")
  125.         #endif
  126.     #endif
  127. #endif
  128.  
  129. #ifdef _DLL
  130.     #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
  131.         #pragma comment(lib, "msvcrtd.lib")
  132.     #else
  133.         #pragma comment(lib, "msvcrt.lib")
  134.     #endif
  135. #else
  136. #ifdef _MT
  137.     #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
  138.         #pragma comment(lib, "libcmtd.lib")
  139.     #else
  140.         #pragma comment(lib, "libcmt.lib")
  141.     #endif
  142. #else
  143.     #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
  144.         #pragma comment(lib, "libcd.lib")
  145.     #else
  146.         #pragma comment(lib, "libc.lib")
  147.     #endif
  148. #endif
  149. #endif
  150.  
  151. #pragma comment(lib, "kernel32.lib")
  152. #pragma comment(lib, "user32.lib")
  153. #pragma comment(lib, "gdi32.lib")
  154. #pragma comment(lib, "comdlg32.lib")
  155. #pragma comment(lib, "winspool.lib")
  156. #pragma comment(lib, "advapi32.lib")
  157. #pragma comment(lib, "shell32.lib")
  158. #pragma comment(lib, "comctl32.lib")
  159.  
  160. // force inclusion of NOLIB.OBJ for /disallowlib directives
  161. #pragma comment(linker, "/include:__afxForceEXCLUDE")
  162. #endif // _WIN32_WCE
  163.  
  164. // force inclusion of DLLMODUL.OBJ for _USRDLL
  165. #ifdef _USRDLL
  166. #pragma comment(linker, "/include:__afxForceUSRDLL")
  167. #if (_WIN32_WCE == 201) && defined(_WIN32_WCE_EMULATION)
  168. // WinCE: Also pull in alternative _DllMainCRTStartup.
  169. #pragma comment(linker, "/include:__wce_afxForceUSRDLL")
  170. #pragma comment(linker, "/entry:wce_DllMainCRTStartup")
  171. #endif // _WIN32_WCE
  172. #endif
  173.  
  174. // force inclusion of STDAFX.OBJ for precompiled types
  175. #ifdef _AFXDLL
  176. #pragma comment(linker, "/include:__afxForceSTDAFX")
  177. #endif
  178.  
  179. #endif //!_AFX_NOFORCE_LIBS
  180. #if (_WIN32_WCE == 201) && defined(_WIN32_WCE_EMULATION)
  181. // WinCE: For PSPC emulation (AlderFE CRT), we get multiple definitions of 
  182. // _DllMain@12.  We let wcedll.cpp implement the entry point, and rename 
  183. // DllMain to ensure the right one gets used.
  184. #define DllMain wce_DllMain
  185. #endif // _WIN32_WCE
  186. /////////////////////////////////////////////////////////////////////////////
  187. // Classes declared in this file
  188. //   in addition to standard primitive data types and various helper macros
  189.  
  190. struct CRuntimeClass;          // object type information
  191.  
  192. class CObject;                        // the root of all objects classes
  193.  
  194.     class CException;                 // the root of all exceptions
  195.         class CArchiveException;      // archive exception
  196.         class CFileException;         // file exception
  197.         class CSimpleException;
  198.             class CMemoryException;       // out-of-memory exception
  199.             class CNotSupportedException; // feature not supported exception
  200.  
  201.     class CFile;                      // raw binary file
  202.         class CStdioFile;             // buffered stdio text/binary file
  203.         class CMemFile;               // memory based file
  204.  
  205. // Non CObject classes
  206. class CString;                        // growable string type
  207. class CTimeSpan;                      // time/date difference
  208. class CTime;                          // absolute time/date
  209. struct CFileStatus;                   // file status information
  210. struct CMemoryState;                  // diagnostic memory support
  211.  
  212. class CArchive;                       // object persistence tool
  213. class CDumpContext;                   // object diagnostic dumping
  214.  
  215. /////////////////////////////////////////////////////////////////////////////
  216. // Other includes from standard "C" runtimes
  217.  
  218. #ifndef _INC_STRING
  219.     #include <string.h>
  220. #endif
  221. #ifndef _INC_STDIO
  222.     #include <stdio.h>
  223. #endif
  224. #ifndef _INC_STDLIB
  225.     #include <stdlib.h>
  226. #endif
  227. #ifndef _INC_TIME
  228.     #include <time.h>
  229. #endif
  230. #ifndef _INC_LIMITS
  231.     #include <limits.h>
  232. #endif
  233. #ifndef _INC_STDDEF
  234.     #include <stddef.h>
  235. #endif
  236. #ifndef _INC_STDARG
  237.     #include <stdarg.h>
  238. #endif
  239.  
  240. #ifndef _AFX_NO_DEBUG_CRT
  241. #ifndef _INC_CRTDBG
  242.     #include <crtdbg.h>
  243. #endif
  244. #endif // _AFX_NO_DEBUG_CRT
  245.  
  246. #ifdef _AFX_OLD_EXCEPTIONS
  247. // use setjmp and helper functions instead of C++ keywords
  248. #ifndef _INC_SETJMP
  249.     #pragma warning(disable: 4611)
  250.     #include <setjmp.h>
  251. #endif
  252. #endif
  253.  
  254. #ifdef _AFX_PACKING
  255. #pragma pack(push, _AFX_PACKING)
  256. #endif
  257.  
  258. /////////////////////////////////////////////////////////////////////////////
  259. // Basic types
  260.  
  261. // abstract iteration position
  262. struct __POSITION { };
  263. typedef __POSITION* POSITION;
  264.  
  265. struct _AFX_DOUBLE  { BYTE doubleBits[sizeof(double)]; };
  266. struct _AFX_FLOAT   { BYTE floatBits[sizeof(float)]; };
  267.  
  268. // Standard constants
  269. #undef FALSE
  270. #undef TRUE
  271. #undef NULL
  272.  
  273. #define FALSE   0
  274. #define TRUE    1
  275. #define NULL    0
  276.  
  277. /////////////////////////////////////////////////////////////////////////////
  278. // Diagnostic support
  279.  
  280. #ifdef _DEBUG
  281.  
  282. BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine);
  283.  
  284. void AFX_CDECL AfxTrace(LPCTSTR lpszFormat, ...);
  285. // Note: file names are still ANSI strings (filenames rarely need UNICODE)
  286. void AFXAPI AfxAssertValidObject(const CObject* pOb,
  287.                 LPCSTR lpszFileName, int nLine);
  288. void AFXAPI AfxDump(const CObject* pOb); // Dump an object from CodeView
  289.  
  290. #define TRACE              ::AfxTrace
  291. #define THIS_FILE          __FILE__
  292. #if defined(_WIN32_WCE)
  293. #undef ASSERT
  294. #endif // _WIN32_WCE
  295. #define ASSERT(f) \
  296.     do \
  297.     { \
  298.     if (!(f) && AfxAssertFailedLine(THIS_FILE, __LINE__)) \
  299.         AfxDebugBreak(); \
  300.     } while (0) \
  301.  
  302. #define VERIFY(f)          ASSERT(f)
  303. #define ASSERT_VALID(pOb)  (::AfxAssertValidObject(pOb, THIS_FILE, __LINE__))
  304. #define DEBUG_ONLY(f)      (f)
  305.  
  306. // The following trace macros are provided for backward compatiblity
  307. //  (they also take a fixed number of parameters which provides
  308. //   some amount of extra error checking)
  309. #define TRACE0(sz)              ::AfxTrace(_T("%s"), _T(sz))
  310. #define TRACE1(sz, p1)          ::AfxTrace(_T(sz), p1)
  311. #define TRACE2(sz, p1, p2)      ::AfxTrace(_T(sz), p1, p2)
  312. #define TRACE3(sz, p1, p2, p3)  ::AfxTrace(_T(sz), p1, p2, p3)
  313.  
  314. // These AFX_DUMP macros also provided for backward compatibility
  315. #define AFX_DUMP0(dc, sz)   dc << _T(sz)
  316. #define AFX_DUMP1(dc, sz, p1) dc << _T(sz) << p1
  317.  
  318. #else   // _DEBUG
  319.  
  320. #if defined(_WIN32_WCE)
  321. #undef ASSERT
  322. #endif // _WIN32_WCE
  323. #define ASSERT(f)          ((void)0)
  324. #define VERIFY(f)          ((void)(f))
  325. #define ASSERT_VALID(pOb)  ((void)0)
  326. #define DEBUG_ONLY(f)      ((void)0)
  327. inline void AFX_CDECL AfxTrace(LPCTSTR, ...) { }
  328. #define TRACE              1 ? (void)0 : ::AfxTrace
  329. #define TRACE0(sz)
  330. #define TRACE1(sz, p1)
  331. #define TRACE2(sz, p1, p2)
  332. #define TRACE3(sz, p1, p2, p3)
  333.  
  334. #endif // !_DEBUG
  335.  
  336. #define ASSERT_POINTER(p, type) \
  337.     ASSERT(((p) != NULL) && AfxIsValidAddress((p), sizeof(type), FALSE))
  338.  
  339. #define ASSERT_NULL_OR_POINTER(p, type) \
  340.     ASSERT(((p) == NULL) || AfxIsValidAddress((p), sizeof(type), FALSE))
  341.  
  342. /////////////////////////////////////////////////////////////////////////////
  343. // Turn off warnings for /W4
  344. // To resume any of these warning: #pragma warning(default: 4xxx)
  345. // which should be placed after the AFX include files
  346. #ifndef ALL_WARNINGS
  347. // warnings generated with common MFC/Windows code
  348. #pragma warning(disable: 4127)  // constant expression for TRACE/ASSERT
  349. #pragma warning(disable: 4134)  // message map member fxn casts
  350. #pragma warning(disable: 4201)  // nameless unions are part of C++
  351. #pragma warning(disable: 4511)  // private copy constructors are good to have
  352. #pragma warning(disable: 4512)  // private operator= are good to have
  353. #pragma warning(disable: 4514)  // unreferenced inlines are common
  354. #pragma warning(disable: 4710)  // private constructors are disallowed
  355. #pragma warning(disable: 4705)  // statement has no effect in optimized code
  356. #pragma warning(disable: 4191)  // pointer-to-function casting
  357. // warnings caused by normal optimizations
  358. #ifndef _DEBUG
  359. #pragma warning(disable: 4701)  // local variable *may* be used without init
  360. #pragma warning(disable: 4702)  // unreachable code caused by optimizations
  361. #pragma warning(disable: 4791)  // loss of debugging info in release version
  362. #pragma warning(disable: 4189)  // initialized but unused variable
  363. #pragma warning(disable: 4390)  // empty controlled statement 
  364. #endif
  365. // warnings specific to _AFXDLL version
  366. #ifdef _AFXDLL
  367. #pragma warning(disable: 4204)  // non-constant aggregate initializer
  368. #endif
  369. #ifdef _AFXDLL
  370. #pragma warning(disable: 4275)  // deriving exported class from non-exported
  371. #pragma warning(disable: 4251)  // using non-exported as public in exported
  372. #endif
  373. #endif //!ALL_WARNINGS
  374.  
  375. #ifdef _DEBUG
  376. #define UNUSED(x)
  377. #else
  378. #define UNUSED(x) x
  379. #endif
  380. #define UNUSED_ALWAYS(x) x
  381.  
  382. /////////////////////////////////////////////////////////////////////////////
  383. // Other implementation helpers
  384.  
  385. #define BEFORE_START_POSITION ((POSITION)-1L)
  386.  
  387. /////////////////////////////////////////////////////////////////////////////
  388. // explicit initialization for general purpose classes
  389.  
  390. BOOL AFXAPI AfxInitialize(BOOL bDLL = FALSE, DWORD dwVersion = _MFC_VER);
  391.  
  392. #undef AFX_DATA
  393. #define AFX_DATA AFX_CORE_DATA
  394.  
  395. #if defined(_WIN32_WCE) 
  396. #include "wcealt.h"
  397. #if defined(_AFX_CORE_IMPL) || defined(_AFX_OLE_IMPL)
  398. #include "wceimpl.h"
  399. #endif
  400. #endif // _WIN32_WCE
  401. /////////////////////////////////////////////////////////////////////////////
  402. // Basic object model
  403.  
  404. struct CRuntimeClass
  405. {
  406. // Attributes
  407.     LPCSTR m_lpszClassName;
  408.     int m_nObjectSize;
  409.     UINT m_wSchema; // schema number of the loaded class
  410.     CObject* (PASCAL* m_pfnCreateObject)(); // NULL => abstract class
  411. #ifdef _AFXDLL
  412.     CRuntimeClass* (PASCAL* m_pfnGetBaseClass)();
  413. #else
  414.     CRuntimeClass* m_pBaseClass;
  415. #endif
  416.  
  417. // Operations
  418.     CObject* CreateObject();
  419.     BOOL IsDerivedFrom(const CRuntimeClass* pBaseClass) const;
  420.  
  421. // Implementation
  422.     void Store(CArchive& ar) const;
  423.     static CRuntimeClass* PASCAL Load(CArchive& ar, UINT* pwSchemaNum);
  424.  
  425.     // CRuntimeClass objects linked together in simple list
  426.     CRuntimeClass* m_pNextClass;       // linked list of registered classes
  427. };
  428.  
  429. /////////////////////////////////////////////////////////////////////////////
  430. // Strings
  431.  
  432. #ifndef _OLEAUTO_H_
  433. #ifdef OLE2ANSI
  434.     typedef LPSTR BSTR;
  435. #else
  436.     typedef LPWSTR BSTR;// must (semantically) match typedef in oleauto.h
  437. #endif
  438. #endif
  439.  
  440. struct CStringData
  441. {
  442.     long nRefs;     // reference count
  443.     int nDataLength;
  444.     int nAllocLength;
  445.     // TCHAR data[nAllocLength]
  446.  
  447.     TCHAR* data()
  448.         { return (TCHAR*)(this+1); }
  449. };
  450.  
  451. class CString
  452. {
  453. public:
  454. // Constructors
  455.     CString();
  456.     CString(const CString& stringSrc);
  457.     CString(TCHAR ch, int nRepeat = 1);
  458.     CString(LPCSTR lpsz);
  459.     CString(LPCWSTR lpsz);
  460.     CString(LPCSTR lpch, int nLength);
  461.     CString(LPCWSTR lpch, int nLength);
  462.     CString(const unsigned char* psz);
  463.  
  464. // Attributes & Operations
  465.     // as an array of characters
  466.     int GetLength() const;
  467.     BOOL IsEmpty() const;
  468.     void Empty();                       // free up the data
  469.  
  470.     TCHAR GetAt(int nIndex) const;      // 0 based
  471.     TCHAR operator[](int nIndex) const; // same as GetAt
  472.     void SetAt(int nIndex, TCHAR ch);
  473.     operator LPCTSTR() const;           // as a C string
  474.  
  475.     // overloaded assignment
  476.     const CString& operator=(const CString& stringSrc);
  477.     const CString& operator=(TCHAR ch);
  478. #ifdef _UNICODE
  479.     const CString& operator=(char ch);
  480. #endif
  481.     const CString& operator=(LPCSTR lpsz);
  482.     const CString& operator=(LPCWSTR lpsz);
  483.     const CString& operator=(const unsigned char* psz);
  484.  
  485.     // string concatenation
  486.     const CString& operator+=(const CString& string);
  487.     const CString& operator+=(TCHAR ch);
  488. #ifdef _UNICODE
  489.     const CString& operator+=(char ch);
  490. #endif
  491.     const CString& operator+=(LPCTSTR lpsz);
  492.  
  493.     friend CString AFXAPI operator+(const CString& string1,
  494.             const CString& string2);
  495.     friend CString AFXAPI operator+(const CString& string, TCHAR ch);
  496.     friend CString AFXAPI operator+(TCHAR ch, const CString& string);
  497. #ifdef _UNICODE
  498.     friend CString AFXAPI operator+(const CString& string, char ch);
  499.     friend CString AFXAPI operator+(char ch, const CString& string);
  500. #endif
  501.     friend CString AFXAPI operator+(const CString& string, LPCTSTR lpsz);
  502.     friend CString AFXAPI operator+(LPCTSTR lpsz, const CString& string);
  503.  
  504.     // string comparison
  505.     int Compare(LPCTSTR lpsz) const;        // straight character
  506.     int CompareNoCase(LPCTSTR lpsz) const;  // ignore case
  507. WCE_DEL int Collate(LPCTSTR lpsz) const;        // NLS aware, case sensitive
  508. WCE_DEL int CollateNoCase(LPCTSTR lpsz) const;    // NLS aware, case insensitive
  509.  
  510.     // simple sub-string extraction
  511.     CString Mid(int nFirst, int nCount) const;
  512.     CString Mid(int nFirst) const;
  513.     CString Left(int nCount) const;
  514.     CString Right(int nCount) const;
  515.  
  516.     CString SpanIncluding(LPCTSTR lpszCharSet) const;
  517.     CString SpanExcluding(LPCTSTR lpszCharSet) const;
  518.  
  519.     // upper/lower/reverse conversion
  520.     void MakeUpper();
  521.     void MakeLower();
  522.     void MakeReverse();
  523.  
  524.     // trimming whitespace (either side)
  525.     void TrimRight();
  526.     void TrimLeft();
  527.  
  528.     // trimming anything (either side)
  529.     void TrimRight(TCHAR chTarget);
  530.     void TrimRight(LPCTSTR lpszTargets);
  531.     void TrimLeft(TCHAR chTarget);
  532.     void TrimLeft(LPCTSTR lpszTargets);
  533.  
  534.     // advanced manipulation
  535.     int Replace(TCHAR chOld, TCHAR chNew);
  536.     int Replace(LPCTSTR lpszOld, LPCTSTR lpszNew);
  537.     int Remove(TCHAR chRemove);
  538.     int Insert(int nIndex, TCHAR ch);
  539.     int Insert(int nIndex, LPCTSTR pstr);
  540.     int Delete(int nIndex, int nCount = 1);
  541.  
  542.     // searching (return starting index, or -1 if not found)
  543.     // look for a single character match
  544.     int Find(TCHAR ch) const;               // like "C" strchr
  545.     int ReverseFind(TCHAR ch) const;
  546.     int Find(TCHAR ch, int nStart) const;
  547.     int FindOneOf(LPCTSTR lpszCharSet) const;
  548.  
  549.     // look for a specific sub-string
  550.     int Find(LPCTSTR lpszSub) const;        // like "C" strstr
  551.     int Find(LPCTSTR lpszSub, int nStart) const;
  552.  
  553.     // simple formatting
  554.     void AFX_CDECL Format(LPCTSTR lpszFormat, ...);
  555.     void AFX_CDECL Format(UINT nFormatID, ...);
  556.     void FormatV(LPCTSTR lpszFormat, va_list argList);
  557.  
  558.     // formatting for localization (uses FormatMessage API)
  559.     void AFX_CDECL FormatMessage(LPCTSTR lpszFormat, ...);
  560.     void AFX_CDECL FormatMessage(UINT nFormatID, ...);
  561.  
  562.     // input and output
  563. #ifdef _DEBUG
  564.     friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,
  565.                 const CString& string);
  566. #endif
  567.     friend CArchive& AFXAPI operator<<(CArchive& ar, const CString& string);
  568.     friend CArchive& AFXAPI operator>>(CArchive& ar, CString& string);
  569.  
  570.     // Windows support
  571.     BOOL LoadString(UINT nID);          // load from string resource
  572.                                         // 255 chars max
  573. #ifndef _UNICODE
  574.     // ANSI <-> OEM support (convert string in place)
  575.     void AnsiToOem();
  576.     void OemToAnsi();
  577. #endif
  578.  
  579. #ifndef _AFX_NO_BSTR_SUPPORT
  580.     // OLE BSTR support (use for OLE automation)
  581.     BSTR AllocSysString() const;
  582.     BSTR SetSysString(BSTR* pbstr) const;
  583. #endif
  584.  
  585.     // Access to string implementation buffer as "C" character array
  586.     LPTSTR GetBuffer(int nMinBufLength);
  587.     void ReleaseBuffer(int nNewLength = -1);
  588.     LPTSTR GetBufferSetLength(int nNewLength);
  589.     void FreeExtra();
  590.  
  591.     // Use LockBuffer/UnlockBuffer to turn refcounting off
  592.     LPTSTR LockBuffer();
  593.     void UnlockBuffer();
  594.  
  595. // Implementation
  596. public:
  597.     ~CString();
  598.     int GetAllocLength() const;
  599.  
  600. protected:
  601.     LPTSTR m_pchData;   // pointer to ref counted string data
  602.  
  603.     // implementation helpers
  604.     CStringData* GetData() const;
  605.     void Init();
  606.     void AllocCopy(CString& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
  607.     void AllocBuffer(int nLen);
  608.     void AssignCopy(int nSrcLen, LPCTSTR lpszSrcData);
  609.     void ConcatCopy(int nSrc1Len, LPCTSTR lpszSrc1Data, int nSrc2Len, LPCTSTR lpszSrc2Data);
  610.     void ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData);
  611.     void CopyBeforeWrite();
  612.     void AllocBeforeWrite(int nLen);
  613.     void Release();
  614.     static void PASCAL Release(CStringData* pData);
  615.     static int PASCAL SafeStrlen(LPCTSTR lpsz);
  616.     static void FASTCALL FreeData(CStringData* pData);
  617. };
  618.  
  619. // Compare helpers
  620. bool AFXAPI operator==(const CString& s1, const CString& s2);
  621. bool AFXAPI operator==(const CString& s1, LPCTSTR s2);
  622. bool AFXAPI operator==(LPCTSTR s1, const CString& s2);
  623. bool AFXAPI operator!=(const CString& s1, const CString& s2);
  624. bool AFXAPI operator!=(const CString& s1, LPCTSTR s2);
  625. bool AFXAPI operator!=(LPCTSTR s1, const CString& s2);
  626. bool AFXAPI operator<(const CString& s1, const CString& s2);
  627. bool AFXAPI operator<(const CString& s1, LPCTSTR s2);
  628. bool AFXAPI operator<(LPCTSTR s1, const CString& s2);
  629. bool AFXAPI operator>(const CString& s1, const CString& s2);
  630. bool AFXAPI operator>(const CString& s1, LPCTSTR s2);
  631. bool AFXAPI operator>(LPCTSTR s1, const CString& s2);
  632. bool AFXAPI operator<=(const CString& s1, const CString& s2);
  633. bool AFXAPI operator<=(const CString& s1, LPCTSTR s2);
  634. bool AFXAPI operator<=(LPCTSTR s1, const CString& s2);
  635. bool AFXAPI operator>=(const CString& s1, const CString& s2);
  636. bool AFXAPI operator>=(const CString& s1, LPCTSTR s2);
  637. bool AFXAPI operator>=(LPCTSTR s1, const CString& s2);
  638.  
  639. // conversion helpers
  640. int AFX_CDECL _wcstombsz(char* mbstr, const wchar_t* wcstr, size_t count);
  641. int AFX_CDECL _mbstowcsz(wchar_t* wcstr, const char* mbstr, size_t count);
  642.  
  643. // Globals
  644. extern AFX_DATA TCHAR afxChNil;
  645. #ifdef _AFXDLL
  646. const CString& AFXAPI AfxGetEmptyString();
  647. #define afxEmptyString AfxGetEmptyString()
  648. #else
  649. extern LPCTSTR _afxPchNil;
  650. #define afxEmptyString ((CString&)*(CString*)&_afxPchNil)
  651. #endif
  652.  
  653. /////////////////////////////////////////////////////////////////////////////
  654. // class CObject is the root of all compliant objects
  655.  
  656. #ifdef _AFXDLL
  657. class CObject
  658. #else
  659. class AFX_NOVTABLE CObject
  660. #endif
  661. {
  662. public:
  663.  
  664. // Object model (types, destruction, allocation)
  665.     virtual CRuntimeClass* GetRuntimeClass() const;
  666.     virtual ~CObject();  // virtual destructors are necessary
  667.  
  668.     // Diagnostic allocations
  669.     void* PASCAL operator new(size_t nSize);
  670.     void* PASCAL operator new(size_t, void* p);
  671.     void PASCAL operator delete(void* p);
  672. #if _MSC_VER >= 1200
  673.     void PASCAL operator delete(void* p, void* pPlace);
  674. #endif
  675.  
  676. #if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
  677.     // for file name/line number tracking using DEBUG_NEW
  678.     void* PASCAL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
  679. #if _MSC_VER >= 1200
  680.     void PASCAL operator delete(void *p, LPCSTR lpszFileName, int nLine);
  681. #endif
  682. #endif
  683.  
  684.     // Disable the copy constructor and assignment by default so you will get
  685.     //   compiler errors instead of unexpected behaviour if you pass objects
  686.     //   by value or assign objects.
  687. protected:
  688.     CObject();
  689. private:
  690.     CObject(const CObject& objectSrc);              // no implementation
  691.     void operator=(const CObject& objectSrc);       // no implementation
  692.  
  693. // Attributes
  694. public:
  695.     BOOL IsSerializable() const;
  696.     BOOL IsKindOf(const CRuntimeClass* pClass) const;
  697.  
  698. // Overridables
  699.     virtual void Serialize(CArchive& ar);
  700.  
  701. #if defined(_DEBUG) || defined(_AFXDLL)
  702.     // Diagnostic Support
  703.     virtual void AssertValid() const;
  704.     virtual void Dump(CDumpContext& dc) const;
  705. #endif
  706.  
  707. // Implementation
  708. public:
  709.     static const AFX_DATA CRuntimeClass classCObject;
  710. #ifdef _AFXDLL
  711.     static CRuntimeClass* PASCAL _GetBaseClass();
  712. #endif
  713. };
  714.  
  715. // Helper macros
  716. #define RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name))
  717. #define ASSERT_KINDOF(class_name, object) \
  718.     ASSERT((object)->IsKindOf(RUNTIME_CLASS(class_name)))
  719.  
  720. // RTTI helper macros/functions
  721. const CObject* AFX_CDECL AfxDynamicDownCast(CRuntimeClass* pClass, const CObject* pObject);
  722. CObject* AFX_CDECL AfxDynamicDownCast(CRuntimeClass* pClass, CObject* pObject);
  723. #define DYNAMIC_DOWNCAST(class_name, object) \
  724.     (class_name*)AfxDynamicDownCast(RUNTIME_CLASS(class_name), object)
  725.  
  726. #ifdef _DEBUG
  727. const CObject* AFX_CDECL AfxStaticDownCast(CRuntimeClass* pClass, const CObject* pObject);
  728. CObject* AFX_CDECL AfxStaticDownCast(CRuntimeClass* pClass, CObject* pObject);
  729. #define STATIC_DOWNCAST(class_name, object) \
  730.     ((class_name*)AfxStaticDownCast(RUNTIME_CLASS(class_name), object))
  731. #else
  732. #define STATIC_DOWNCAST(class_name, object) ((class_name*)object)
  733. #endif
  734.  
  735. //////////////////////////////////////////////////////////////////////////////
  736. // Helper macros for declaring CRuntimeClass compatible classes
  737.  
  738. #ifdef _AFXDLL
  739. #define DECLARE_DYNAMIC(class_name) \
  740. protected: \
  741.     static CRuntimeClass* PASCAL _GetBaseClass(); \
  742. public: \
  743.     static const AFX_DATA CRuntimeClass class##class_name; \
  744.     virtual CRuntimeClass* GetRuntimeClass() const; \
  745.  
  746. #define _DECLARE_DYNAMIC(class_name) \
  747. protected: \
  748.     static CRuntimeClass* PASCAL _GetBaseClass(); \
  749. public: \
  750.     static AFX_DATA CRuntimeClass class##class_name; \
  751.     virtual CRuntimeClass* GetRuntimeClass() const; \
  752.  
  753. #else
  754. #define DECLARE_DYNAMIC(class_name) \
  755. public: \
  756.     static const AFX_DATA CRuntimeClass class##class_name; \
  757.     virtual CRuntimeClass* GetRuntimeClass() const; \
  758.  
  759. #define _DECLARE_DYNAMIC(class_name) \
  760. public: \
  761.     static AFX_DATA CRuntimeClass class##class_name; \
  762.     virtual CRuntimeClass* GetRuntimeClass() const; \
  763.  
  764. #endif
  765.  
  766. // not serializable, but dynamically constructable
  767. #define DECLARE_DYNCREATE(class_name) \
  768.     DECLARE_DYNAMIC(class_name) \
  769.     static CObject* PASCAL CreateObject();
  770.  
  771. #define _DECLARE_DYNCREATE(class_name) \
  772.     _DECLARE_DYNAMIC(class_name) \
  773.     static CObject* PASCAL CreateObject();
  774.  
  775. #define DECLARE_SERIAL(class_name) \
  776.     _DECLARE_DYNCREATE(class_name) \
  777.     AFX_API friend CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb);
  778.  
  779. // generate static object constructor for class registration
  780. void AFXAPI AfxClassInit(CRuntimeClass* pNewClass);
  781. struct AFX_CLASSINIT
  782.     { AFX_CLASSINIT(CRuntimeClass* pNewClass) { AfxClassInit(pNewClass); } };
  783. struct AFX_CLASSINIT_COMPAT
  784.     { AFX_CLASSINIT_COMPAT(CRuntimeClass* pNewClass); };
  785.  
  786. #ifdef _AFXDLL
  787. #define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
  788.     CRuntimeClass* PASCAL class_name::_GetBaseClass() \
  789.         { return RUNTIME_CLASS(base_class_name); } \
  790.     AFX_COMDAT const AFX_DATADEF CRuntimeClass class_name::class##class_name = { \
  791.         #class_name, sizeof(class class_name), wSchema, pfnNew, \
  792.             &class_name::_GetBaseClass, NULL }; \
  793.     CRuntimeClass* class_name::GetRuntimeClass() const \
  794.         { return RUNTIME_CLASS(class_name); } \
  795.  
  796. #define _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
  797.     CRuntimeClass* PASCAL class_name::_GetBaseClass() \
  798.         { return RUNTIME_CLASS(base_class_name); } \
  799.     AFX_COMDAT AFX_DATADEF CRuntimeClass class_name::class##class_name = { \
  800.         #class_name, sizeof(class class_name), wSchema, pfnNew, \
  801.             &class_name::_GetBaseClass, NULL }; \
  802.     CRuntimeClass* class_name::GetRuntimeClass() const \
  803.         { return RUNTIME_CLASS(class_name); } \
  804.  
  805. #else
  806. #define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
  807.     AFX_COMDAT const AFX_DATADEF CRuntimeClass class_name::class##class_name = { \
  808.         #class_name, sizeof(class class_name), wSchema, pfnNew, \
  809.             RUNTIME_CLASS(base_class_name), NULL }; \
  810.     CRuntimeClass* class_name::GetRuntimeClass() const \
  811.         { return RUNTIME_CLASS(class_name); } \
  812.  
  813. #define _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
  814.     AFX_DATADEF CRuntimeClass class_name::class##class_name = { \
  815.         #class_name, sizeof(class class_name), wSchema, pfnNew, \
  816.             RUNTIME_CLASS(base_class_name), NULL }; \
  817.     CRuntimeClass* class_name::GetRuntimeClass() const \
  818.         { return RUNTIME_CLASS(class_name); } \
  819.  
  820. #endif
  821.  
  822. #define IMPLEMENT_DYNAMIC(class_name, base_class_name) \
  823.     IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, NULL)
  824.  
  825. #define IMPLEMENT_DYNCREATE(class_name, base_class_name) \
  826.     CObject* PASCAL class_name::CreateObject() \
  827.         { return new class_name; } \
  828.     IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, \
  829.         class_name::CreateObject)
  830.  
  831. #define IMPLEMENT_SERIAL(class_name, base_class_name, wSchema) \
  832.     CObject* PASCAL class_name::CreateObject() \
  833.         { return new class_name; } \
  834.     _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, \
  835.         class_name::CreateObject) \
  836.     AFX_CLASSINIT _init_##class_name(RUNTIME_CLASS(class_name)); \
  837.     CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \
  838.         { pOb = (class_name*) ar.ReadObject(RUNTIME_CLASS(class_name)); \
  839.             return ar; } \
  840.  
  841. // optional bit for schema number that enables object versioning
  842. #define VERSIONABLE_SCHEMA  (0x80000000)
  843.  
  844. /////////////////////////////////////////////////////////////////////////////
  845. // other helpers
  846.  
  847. // zero fill everything after the vtbl pointer
  848. #define AFX_ZERO_INIT_OBJECT(base_class) \
  849.     memset(((base_class*)this)+1, 0, sizeof(*this) - sizeof(class base_class));
  850.  
  851.  
  852. /////////////////////////////////////////////////////////////////////////////
  853. // Exceptions
  854.  
  855. #ifdef _AFXDLL
  856. class CException : public CObject
  857. #else
  858. class AFX_NOVTABLE CException : public CObject
  859. #endif
  860. {
  861.     // abstract class for dynamic type checking
  862.     DECLARE_DYNAMIC(CException)
  863.  
  864. public:
  865. // Constructors
  866.     CException();   // sets m_bAutoDelete = TRUE
  867.     CException(BOOL bAutoDelete);   // sets m_bAutoDelete = bAutoDelete
  868.  
  869. // Operations
  870.     void Delete();  // use to delete exception in 'catch' block
  871.  
  872.     virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  873.         PUINT pnHelpContext = NULL);
  874.     virtual int ReportError(UINT nType = MB_OK, UINT nMessageID = 0);
  875.  
  876. // Implementation (setting m_bAutoDelete to FALSE is advanced)
  877. public:
  878.     virtual ~CException();
  879.     BOOL m_bAutoDelete;
  880. #ifdef _DEBUG
  881.     void PASCAL operator delete(void* pbData);
  882. #if _MSC_VER >= 1200
  883.     void PASCAL operator delete(void* pbData, LPCSTR lpszFileName, int nLine);
  884. #endif
  885. protected:
  886.     BOOL m_bReadyForDelete;
  887. #endif
  888. };
  889.  
  890. #ifdef _AFXDLL
  891. class CSimpleException : public CException
  892. #else
  893. class AFX_NOVTABLE CSimpleException : public CException
  894. #endif
  895. {
  896.     // base class for resource-critical MFC exceptions
  897.     // handles ownership and initialization of an error message
  898.  
  899. public:
  900. // Constructors
  901.     CSimpleException();
  902.     CSimpleException(BOOL bAutoDelete);
  903.  
  904. // Operations
  905.     virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  906.         PUINT pnHelpContext = NULL);
  907.  
  908. // Implementation (setting m_bAutoDelete to FALSE is advanced)
  909. public:
  910.     virtual ~CSimpleException();
  911.     BOOL m_bAutoDelete;
  912.  
  913.     void InitString();      // used during MFC initialization
  914.  
  915. protected:
  916.     BOOL m_bInitialized;
  917.     BOOL m_bLoaded;
  918.     TCHAR m_szMessage[128];
  919.     UINT m_nResourceID;
  920.  
  921. #ifdef _DEBUG
  922.     BOOL m_bReadyForDelete;
  923. #endif
  924. };
  925.  
  926. // helper routines for non-C++ EH implementations
  927. #ifdef _AFX_OLD_EXCEPTIONS
  928.     BOOL AFXAPI AfxCatchProc(CRuntimeClass* pClass);
  929.     void AFXAPI AfxThrow(CException* pException);
  930. #else
  931.     // for THROW_LAST auto-delete backward compatiblity
  932.     void AFXAPI AfxThrowLastCleanup();
  933. #endif
  934.  
  935. // other out-of-line helper functions
  936. void AFXAPI AfxTryCleanup();
  937.  
  938. #ifndef _AFX_JUMPBUF
  939. // Use portable 'jmp_buf' defined by ANSI by default.
  940. #define _AFX_JUMPBUF jmp_buf
  941. #endif
  942.  
  943. // Placed on frame for EXCEPTION linkage, or CException cleanup
  944. struct AFX_EXCEPTION_LINK
  945. {
  946. #ifdef _AFX_OLD_EXCEPTIONS
  947.     union
  948.     {
  949.         _AFX_JUMPBUF m_jumpBuf;
  950.         struct
  951.         {
  952.             void (PASCAL* pfnCleanup)(AFX_EXCEPTION_LINK* pLink);
  953.             void* pvData;       // extra data follows
  954.         } m_callback;       // callback for cleanup (nType != 0)
  955.     };
  956.     UINT m_nType;               // 0 for setjmp, !=0 for user extension
  957. #endif //!_AFX_OLD_EXCEPTIONS
  958.  
  959.     AFX_EXCEPTION_LINK* m_pLinkPrev;    // previous top, next in handler chain
  960.     CException* m_pException;   // current exception (NULL in TRY block)
  961.  
  962.     AFX_EXCEPTION_LINK();       // for initialization and linking
  963.     ~AFX_EXCEPTION_LINK()       // for cleanup and unlinking
  964.         { AfxTryCleanup(); };
  965. };
  966.  
  967. // Exception global state - never access directly
  968. struct AFX_EXCEPTION_CONTEXT
  969. {
  970.     AFX_EXCEPTION_LINK* m_pLinkTop;
  971.  
  972.     // Note: most of the exception context is now in the AFX_EXCEPTION_LINK
  973. };
  974.  
  975. #ifndef _PNH_DEFINED
  976. typedef int (__cdecl * _PNH)( size_t );
  977. #define _PNH_DEFINED
  978. #endif
  979.  
  980. _PNH AFXAPI AfxGetNewHandler();
  981. _PNH AFXAPI AfxSetNewHandler(_PNH pfnNewHandler);
  982. int AFX_CDECL AfxNewHandler(size_t nSize);
  983.  
  984. void AFXAPI AfxAbort();
  985.  
  986. #ifdef _AFX_OLD_EXCEPTIONS
  987.  
  988. // Obsolete and non-portable: setting terminate handler
  989. //  use CWinApp::ProcessWndProcException for Windows apps instead
  990. //  can also use set_terminate which is part of C++ standard library
  991. //      (these are provided for backward compatibility)
  992. void AFXAPI AfxTerminate();
  993. typedef void (AFXAPI* AFX_TERM_PROC)();
  994. AFX_TERM_PROC AFXAPI AfxSetTerminate(AFX_TERM_PROC);
  995.  
  996. #endif
  997.  
  998. /////////////////////////////////////////////////////////////////////////////
  999. // Exception macros using try, catch and throw
  1000. //  (for backward compatibility to previous versions of MFC)
  1001.  
  1002. #ifndef _AFX_OLD_EXCEPTIONS
  1003.  
  1004. #define TRY { AFX_EXCEPTION_LINK _afxExceptionLink; try {
  1005.  
  1006. #define CATCH(class, e) } catch (class* e) \
  1007.     { ASSERT(e->IsKindOf(RUNTIME_CLASS(class))); \
  1008.         _afxExceptionLink.m_pException = e;
  1009.  
  1010. #define AND_CATCH(class, e) } catch (class* e) \
  1011.     { ASSERT(e->IsKindOf(RUNTIME_CLASS(class))); \
  1012.         _afxExceptionLink.m_pException = e;
  1013.  
  1014. #define END_CATCH } }
  1015.  
  1016. #define THROW(e) throw e
  1017. #define THROW_LAST() (AfxThrowLastCleanup(), throw)
  1018.  
  1019. // Advanced macros for smaller code
  1020. #define CATCH_ALL(e) } catch (CException* e) \
  1021.     { { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  1022.         _afxExceptionLink.m_pException = e;
  1023.  
  1024. #define AND_CATCH_ALL(e) } catch (CException* e) \
  1025.     { { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  1026.         _afxExceptionLink.m_pException = e;
  1027.  
  1028. #define END_CATCH_ALL } } }
  1029.  
  1030. #define END_TRY } catch (CException* e) \
  1031.     { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  1032.         _afxExceptionLink.m_pException = e; } }
  1033.  
  1034. #else //_AFX_OLD_EXCEPTIONS
  1035.  
  1036. /////////////////////////////////////////////////////////////////////////////
  1037. // Exception macros using setjmp and longjmp
  1038. //  (for portability to compilers with no support for C++ exception handling)
  1039.  
  1040. #define TRY \
  1041.     { AFX_EXCEPTION_LINK _afxExceptionLink; \
  1042.     if (::setjmp(_afxExceptionLink.m_jumpBuf) == 0)
  1043.  
  1044. #define CATCH(class, e) \
  1045.     else if (::AfxCatchProc(RUNTIME_CLASS(class))) \
  1046.     { class* e = (class*)_afxExceptionLink.m_pException;
  1047.  
  1048. #define AND_CATCH(class, e) \
  1049.     } else if (::AfxCatchProc(RUNTIME_CLASS(class))) \
  1050.     { class* e = (class*)_afxExceptionLink.m_pException;
  1051.  
  1052. #define END_CATCH \
  1053.     } else { ::AfxThrow(NULL); } }
  1054.  
  1055. #define THROW(e) AfxThrow(e)
  1056. #define THROW_LAST() AfxThrow(NULL)
  1057.  
  1058. // Advanced macros for smaller code
  1059. #define CATCH_ALL(e) \
  1060.     else { CException* e = _afxExceptionLink.m_pException;
  1061.  
  1062. #define AND_CATCH_ALL(e) \
  1063.     } else { CException* e = _afxExceptionLink.m_pException;
  1064.  
  1065. #define END_CATCH_ALL } }
  1066.  
  1067. #define END_TRY }
  1068.  
  1069. #endif //_AFX_OLD_EXCEPTIONS
  1070.  
  1071. /////////////////////////////////////////////////////////////////////////////
  1072. // Standard Exception classes
  1073.  
  1074. class CMemoryException : public CSimpleException
  1075. {
  1076.     DECLARE_DYNAMIC(CMemoryException)
  1077. public:
  1078.     CMemoryException();
  1079.  
  1080. // Implementation
  1081. public:
  1082.     CMemoryException(BOOL bAutoDelete);
  1083.     CMemoryException(BOOL bAutoDelete, UINT nResourceID);
  1084.     virtual ~CMemoryException();
  1085. };
  1086.  
  1087. class CNotSupportedException : public CSimpleException
  1088. {
  1089.     DECLARE_DYNAMIC(CNotSupportedException)
  1090. public:
  1091.     CNotSupportedException();
  1092.  
  1093. // Implementation
  1094. public:
  1095.     CNotSupportedException(BOOL bAutoDelete);
  1096.     CNotSupportedException(BOOL bAutoDelete, UINT nResourceID);
  1097.     virtual ~CNotSupportedException();
  1098. };
  1099.  
  1100. class CArchiveException : public CException
  1101. {
  1102.     DECLARE_DYNAMIC(CArchiveException)
  1103. public:
  1104.     enum {
  1105.         none,
  1106.         generic,
  1107.         readOnly,
  1108.         endOfFile,
  1109.         writeOnly,
  1110.         badIndex,
  1111.         badClass,
  1112.         badSchema
  1113.     };
  1114.  
  1115. // Constructor
  1116.     CArchiveException(int cause = CArchiveException::none,
  1117.         LPCTSTR lpszArchiveName = NULL);
  1118.  
  1119. // Attributes
  1120.     int m_cause;
  1121.     CString m_strFileName;
  1122.  
  1123. // Implementation
  1124. public:
  1125.     virtual ~CArchiveException();
  1126. #ifdef _DEBUG
  1127.     virtual void Dump(CDumpContext& dc) const;
  1128. #endif
  1129.     virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  1130.         PUINT pnHelpContext = NULL);
  1131. };
  1132.  
  1133. class CFileException : public CException
  1134. {
  1135.     DECLARE_DYNAMIC(CFileException)
  1136.  
  1137. public:
  1138.     enum {
  1139.         none,
  1140.         generic,
  1141.         fileNotFound,
  1142.         badPath,
  1143.         tooManyOpenFiles,
  1144.         accessDenied,
  1145.         invalidFile,
  1146.         removeCurrentDir,
  1147.         directoryFull,
  1148.         badSeek,
  1149.         hardIO,
  1150.         sharingViolation,
  1151.         lockViolation,
  1152.         diskFull,
  1153.         endOfFile
  1154.     };
  1155.  
  1156. // Constructor
  1157.     CFileException(int cause = CFileException::none, LONG lOsError = -1,
  1158.         LPCTSTR lpszArchiveName = NULL);
  1159.  
  1160. // Attributes
  1161.     int     m_cause;
  1162.     LONG    m_lOsError;
  1163.     CString m_strFileName;
  1164.  
  1165. // Operations
  1166.     // convert a OS dependent error code to a Cause
  1167.     static int PASCAL OsErrorToException(LONG lOsError);
  1168. WCE_DEL    static int PASCAL ErrnoToException(int nErrno);
  1169.  
  1170.     // helper functions to throw exception after converting to a Cause
  1171.     static void PASCAL ThrowOsError(LONG lOsError, LPCTSTR lpszFileName = NULL);
  1172. WCE_DEL    static void PASCAL ThrowErrno(int nErrno, LPCTSTR lpszFileName = NULL);
  1173.  
  1174. // Implementation
  1175. public:
  1176.     virtual ~CFileException();
  1177. #ifdef _DEBUG
  1178.     virtual void Dump(CDumpContext&) const;
  1179. #endif
  1180.     virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  1181.         PUINT pnHelpContext = NULL);
  1182. };
  1183.  
  1184. /////////////////////////////////////////////////////////////////////////////
  1185. // Standard exception throws
  1186.  
  1187. void AFXAPI AfxThrowMemoryException();
  1188. void AFXAPI AfxThrowNotSupportedException();
  1189. void AFXAPI AfxThrowArchiveException(int cause,
  1190.     LPCTSTR lpszArchiveName = NULL);
  1191. void AFXAPI AfxThrowFileException(int cause, LONG lOsError = -1,
  1192.     LPCTSTR lpszFileName = NULL);
  1193.  
  1194. /////////////////////////////////////////////////////////////////////////////
  1195. // File - raw unbuffered disk file I/O
  1196.  
  1197. class CFile : public CObject
  1198. {
  1199.     DECLARE_DYNAMIC(CFile)
  1200.  
  1201. public:
  1202. // Flag values
  1203.     enum OpenFlags {
  1204.         modeRead =          0x0000,
  1205.         modeWrite =         0x0001,
  1206.         modeReadWrite =     0x0002,
  1207.         shareCompat =       0x0000,
  1208.         shareExclusive =    0x0010,
  1209.         shareDenyWrite =    0x0020,
  1210.         shareDenyRead =     0x0030,
  1211.         shareDenyNone =     0x0040,
  1212.         modeNoInherit =     0x0080,
  1213.         modeCreate =        0x1000,
  1214.         modeNoTruncate =    0x2000,
  1215.         typeText =          0x4000, // typeText and typeBinary are used in
  1216.         typeBinary =   (int)0x8000 // derived classes only
  1217.         };
  1218.  
  1219.     enum Attribute {
  1220.         normal =    0x00,
  1221.         readOnly =  0x01,
  1222.         hidden =    0x02,
  1223.         system =    0x04,
  1224.         volume =    0x08,
  1225.         directory = 0x10,
  1226.         archive =   0x20
  1227.         };
  1228.  
  1229.     enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };
  1230.  
  1231.     enum { hFileNull = -1 };
  1232.  
  1233. // Constructors
  1234.     CFile();
  1235.     CFile(int hFile);
  1236.     CFile(LPCTSTR lpszFileName, UINT nOpenFlags);
  1237.  
  1238. // Attributes
  1239.     UINT m_hFile;
  1240.     operator HFILE() const;
  1241.  
  1242.     virtual DWORD GetPosition() const;
  1243.     BOOL GetStatus(CFileStatus& rStatus) const;
  1244.     virtual CString GetFileName() const;
  1245.     virtual CString GetFileTitle() const;
  1246.     virtual CString GetFilePath() const;
  1247.     virtual void SetFilePath(LPCTSTR lpszNewName);
  1248.  
  1249. // Operations
  1250.     virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
  1251.         CFileException* pError = NULL);
  1252.  
  1253.     static void PASCAL Rename(LPCTSTR lpszOldName,
  1254.                 LPCTSTR lpszNewName);
  1255.     static void PASCAL Remove(LPCTSTR lpszFileName);
  1256.     static BOOL PASCAL GetStatus(LPCTSTR lpszFileName,
  1257.                 CFileStatus& rStatus);
  1258.     static void PASCAL SetStatus(LPCTSTR lpszFileName,
  1259.                 const CFileStatus& status);
  1260.  
  1261.     DWORD SeekToEnd();
  1262.     void SeekToBegin();
  1263.  
  1264.     // backward compatible ReadHuge and WriteHuge
  1265.     DWORD ReadHuge(void* lpBuffer, DWORD dwCount);
  1266.     void WriteHuge(const void* lpBuffer, DWORD dwCount);
  1267.  
  1268. // Overridables
  1269. WCE_DEL    virtual CFile* Duplicate() const;
  1270.  
  1271.     virtual LONG Seek(LONG lOff, UINT nFrom);
  1272.     virtual void SetLength(DWORD dwNewLen);
  1273.     virtual DWORD GetLength() const;
  1274.  
  1275.     virtual UINT Read(void* lpBuf, UINT nCount);
  1276.     virtual void Write(const void* lpBuf, UINT nCount);
  1277.  
  1278. WCE_DEL    virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1279. WCE_DEL    virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1280.  
  1281.     virtual void Abort();
  1282.     virtual void Flush();
  1283.     virtual void Close();
  1284.  
  1285. // Implementation
  1286. public:
  1287.     virtual ~CFile();
  1288. #ifdef _DEBUG
  1289.     virtual void AssertValid() const;
  1290.     virtual void Dump(CDumpContext& dc) const;
  1291. #endif
  1292.     enum BufferCommand { bufferRead, bufferWrite, bufferCommit, bufferCheck };
  1293.     virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
  1294.         void** ppBufStart = NULL, void** ppBufMax = NULL);
  1295.  
  1296. protected:
  1297.     BOOL m_bCloseOnDelete;
  1298.     CString m_strFileName;
  1299. };
  1300.  
  1301. /////////////////////////////////////////////////////////////////////////////
  1302. // STDIO file implementation
  1303.  
  1304. class CStdioFile : public CFile
  1305. {
  1306.     DECLARE_DYNAMIC(CStdioFile)
  1307.  
  1308. public:
  1309. // Constructors
  1310.     CStdioFile();
  1311. WCE_DEL    CStdioFile(FILE* pOpenStream);
  1312.     CStdioFile(LPCTSTR lpszFileName, UINT nOpenFlags);
  1313.  
  1314. // Attributes
  1315. WCE_DEL FILE* m_pStream;    // stdio FILE
  1316.                         // m_hFile from base class is _fileno(m_pStream)
  1317.  
  1318. // Operations
  1319.     // reading and writing strings
  1320. WCE_DEL    virtual void WriteString(LPCTSTR lpsz);
  1321. WCE_DEL virtual LPTSTR ReadString(LPTSTR lpsz, UINT nMax);
  1322. WCE_DEL virtual BOOL ReadString(CString& rString);
  1323.  
  1324. // Implementation
  1325. public:
  1326.     virtual ~CStdioFile();
  1327. #ifdef _DEBUG
  1328. WCE_DEL void Dump(CDumpContext& dc) const;
  1329. #endif
  1330. WCE_DEL virtual DWORD GetPosition() const;
  1331. WCE_DEL virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
  1332. WCE_DEL CFileException* pError = NULL);
  1333. WCE_DEL virtual UINT Read(void* lpBuf, UINT nCount);
  1334. WCE_DEL virtual void Write(const void* lpBuf, UINT nCount);
  1335. WCE_DEL virtual LONG Seek(LONG lOff, UINT nFrom);
  1336. WCE_DEL virtual void Abort();
  1337. WCE_DEL virtual void Flush();
  1338. WCE_DEL virtual void Close();
  1339.  
  1340.     // Unsupported APIs
  1341. WCE_DEL virtual CFile* Duplicate() const;
  1342. WCE_DEL virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1343. WCE_DEL virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1344. };
  1345.  
  1346. ////////////////////////////////////////////////////////////////////////////
  1347. // Memory based file implementation
  1348.  
  1349. class CMemFile : public CFile
  1350. {
  1351.     DECLARE_DYNAMIC(CMemFile)
  1352.  
  1353. public:
  1354. // Constructors
  1355.     CMemFile(UINT nGrowBytes = 1024);
  1356.     CMemFile(BYTE* lpBuffer, UINT nBufferSize, UINT nGrowBytes = 0);
  1357.  
  1358. // Operations
  1359.     void Attach(BYTE* lpBuffer, UINT nBufferSize, UINT nGrowBytes = 0);
  1360.     BYTE* Detach();
  1361.  
  1362. // Advanced Overridables
  1363. protected:
  1364.     virtual BYTE* Alloc(DWORD nBytes);
  1365.     virtual BYTE* Realloc(BYTE* lpMem, DWORD nBytes);
  1366.     virtual BYTE* Memcpy(BYTE* lpMemTarget, const BYTE* lpMemSource, UINT nBytes);
  1367.     virtual void Free(BYTE* lpMem);
  1368.     virtual void GrowFile(DWORD dwNewLen);
  1369.  
  1370. // Implementation
  1371. protected:
  1372.     UINT m_nGrowBytes;
  1373.     DWORD m_nPosition;
  1374.     DWORD m_nBufferSize;
  1375.     DWORD m_nFileSize;
  1376.     BYTE* m_lpBuffer;
  1377.     BOOL m_bAutoDelete;
  1378.  
  1379. public:
  1380.     virtual ~CMemFile();
  1381. #ifdef _DEBUG
  1382.     virtual void Dump(CDumpContext& dc) const;
  1383.     virtual void AssertValid() const;
  1384. #endif
  1385.     virtual DWORD GetPosition() const;
  1386.     BOOL GetStatus(CFileStatus& rStatus) const;
  1387.     virtual LONG Seek(LONG lOff, UINT nFrom);
  1388.     virtual void SetLength(DWORD dwNewLen);
  1389.     virtual UINT Read(void* lpBuf, UINT nCount);
  1390.     virtual void Write(const void* lpBuf, UINT nCount);
  1391.     virtual void Abort();
  1392.     virtual void Flush();
  1393.     virtual void Close();
  1394.     virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
  1395.         void** ppBufStart = NULL, void** ppBufMax = NULL);
  1396.  
  1397.     // Unsupported APIs
  1398.     virtual CFile* Duplicate() const;
  1399.     virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1400.     virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1401. };
  1402.  
  1403. #if !defined(_WIN32_WCE)
  1404. ////////////////////////////////////////////////////////////////////////////
  1405. // Local file searches
  1406.  
  1407. class CFileFind : public CObject
  1408. {
  1409. public:
  1410.     CFileFind();
  1411.     virtual ~CFileFind();
  1412.  
  1413. // Attributes
  1414. public:
  1415.     DWORD GetLength() const;
  1416. #if defined(_X86_) || defined(_ALPHA_)
  1417.     __int64 GetLength64() const;
  1418. #endif
  1419.     virtual CString GetFileName() const;
  1420.     virtual CString GetFilePath() const;
  1421.     virtual CString GetFileTitle() const;
  1422.     virtual CString GetFileURL() const;
  1423.     virtual CString GetRoot() const;
  1424.  
  1425.     virtual BOOL GetLastWriteTime(FILETIME* pTimeStamp) const;
  1426.     virtual BOOL GetLastAccessTime(FILETIME* pTimeStamp) const;
  1427.     virtual BOOL GetCreationTime(FILETIME* pTimeStamp) const;
  1428.     virtual BOOL GetLastWriteTime(CTime& refTime) const;
  1429.     virtual BOOL GetLastAccessTime(CTime& refTime) const;
  1430.     virtual BOOL GetCreationTime(CTime& refTime) const;
  1431.  
  1432.     virtual BOOL MatchesMask(DWORD dwMask) const;
  1433.  
  1434.     virtual BOOL IsDots() const;
  1435.     // these aren't virtual because they all use MatchesMask(), which is
  1436.     BOOL IsReadOnly() const;
  1437.     BOOL IsDirectory() const;
  1438.     BOOL IsCompressed() const;
  1439.     BOOL IsSystem() const;
  1440.     BOOL IsHidden() const;
  1441.     BOOL IsTemporary() const;
  1442.     BOOL IsNormal() const;
  1443.     BOOL IsArchived() const;
  1444.  
  1445. // Operations
  1446.     void Close();
  1447.     virtual BOOL FindFile(LPCTSTR pstrName = NULL, DWORD dwUnused = 0);
  1448.     virtual BOOL FindNextFile();
  1449.  
  1450. protected:
  1451.     virtual void CloseContext();
  1452.  
  1453. // Implementation
  1454. protected:
  1455.     void* m_pFoundInfo;
  1456.     void* m_pNextInfo;
  1457.     HANDLE m_hContext;
  1458.     BOOL m_bGotLast;
  1459.     CString m_strRoot;
  1460.     TCHAR m_chDirSeparator;     // not '\\' for Internet classes
  1461.  
  1462. #ifdef _DEBUG
  1463.     void Dump(CDumpContext& dc) const;
  1464.     void AssertValid() const;
  1465. #endif
  1466.  
  1467.     DECLARE_DYNAMIC(CFileFind)
  1468. };
  1469. #endif // _WIN32_WCE_NO_FTP
  1470.  
  1471. /////////////////////////////////////////////////////////////////////////////
  1472. // CTimeSpan and CTime
  1473.  
  1474. class CTimeSpan
  1475. {
  1476. public:
  1477.  
  1478. // Constructors
  1479.     CTimeSpan();
  1480.     CTimeSpan(time_t time);
  1481.     CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs);
  1482.  
  1483.     CTimeSpan(const CTimeSpan& timeSpanSrc);
  1484.     const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);
  1485.  
  1486. // Attributes
  1487.     // extract parts
  1488.     LONG GetDays() const;   // total # of days
  1489.     LONG GetTotalHours() const;
  1490.     int GetHours() const;
  1491.     LONG GetTotalMinutes() const;
  1492.     int GetMinutes() const;
  1493.     LONG GetTotalSeconds() const;
  1494.     int GetSeconds() const;
  1495.  
  1496. // Operations
  1497.     // time math
  1498.     CTimeSpan operator-(CTimeSpan timeSpan) const;
  1499.     CTimeSpan operator+(CTimeSpan timeSpan) const;
  1500.     const CTimeSpan& operator+=(CTimeSpan timeSpan);
  1501.     const CTimeSpan& operator-=(CTimeSpan timeSpan);
  1502.     BOOL operator==(CTimeSpan timeSpan) const;
  1503.     BOOL operator!=(CTimeSpan timeSpan) const;
  1504.     BOOL operator<(CTimeSpan timeSpan) const;
  1505.     BOOL operator>(CTimeSpan timeSpan) const;
  1506.     BOOL operator<=(CTimeSpan timeSpan) const;
  1507.     BOOL operator>=(CTimeSpan timeSpan) const;
  1508.  
  1509. #ifdef _UNICODE
  1510.     // for compatibility with MFC 3.x
  1511.     CString Format(LPCSTR pFormat) const;
  1512. #endif
  1513.     CString Format(LPCTSTR pFormat) const;
  1514.     CString Format(UINT nID) const;
  1515.  
  1516.     // serialization
  1517. #ifdef _DEBUG
  1518.     friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,CTimeSpan timeSpan);
  1519. #endif
  1520.     friend CArchive& AFXAPI operator<<(CArchive& ar, CTimeSpan timeSpan);
  1521.     friend CArchive& AFXAPI operator>>(CArchive& ar, CTimeSpan& rtimeSpan);
  1522.  
  1523. private:
  1524.     time_t m_timeSpan;
  1525.     friend class CTime;
  1526. };
  1527.  
  1528. class CTime
  1529. {
  1530. public:
  1531.  
  1532. // Constructors
  1533.     static CTime PASCAL GetCurrentTime();
  1534.  
  1535.     CTime();
  1536.     CTime(time_t time);
  1537.     CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
  1538.         int nDST = -1);
  1539.     CTime(WORD wDosDate, WORD wDosTime, int nDST = -1);
  1540.     CTime(const CTime& timeSrc);
  1541.  
  1542.     CTime(const SYSTEMTIME& sysTime, int nDST = -1);
  1543.     CTime(const FILETIME& fileTime, int nDST = -1);
  1544.     const CTime& operator=(const CTime& timeSrc);
  1545.     const CTime& operator=(time_t t);
  1546.  
  1547. // Attributes
  1548. WCE_DEL    struct tm* GetGmtTm(struct tm* ptm = NULL) const;
  1549.     struct tm* GetLocalTm(struct tm* ptm = NULL) const;
  1550.     BOOL GetAsSystemTime(SYSTEMTIME& timeDest) const;
  1551.  
  1552.     time_t GetTime() const;
  1553.     int GetYear() const;
  1554.     int GetMonth() const;       // month of year (1 = Jan)
  1555.     int GetDay() const;         // day of month
  1556.     int GetHour() const;
  1557.     int GetMinute() const;
  1558.     int GetSecond() const;
  1559.     int GetDayOfWeek() const;   // 1=Sun, 2=Mon, ..., 7=Sat
  1560.  
  1561. // Operations
  1562.     // time math
  1563.     CTimeSpan operator-(CTime time) const;
  1564.     CTime operator-(CTimeSpan timeSpan) const;
  1565.     CTime operator+(CTimeSpan timeSpan) const;
  1566.     const CTime& operator+=(CTimeSpan timeSpan);
  1567.     const CTime& operator-=(CTimeSpan timeSpan);
  1568.     BOOL operator==(CTime time) const;
  1569.     BOOL operator!=(CTime time) const;
  1570.     BOOL operator<(CTime time) const;
  1571.     BOOL operator>(CTime time) const;
  1572.     BOOL operator<=(CTime time) const;
  1573.     BOOL operator>=(CTime time) const;
  1574.  
  1575.     // formatting using "C" strftime
  1576. WCE_DEL    CString Format(LPCTSTR pFormat) const;
  1577. WCE_DEL    CString FormatGmt(LPCTSTR pFormat) const;
  1578. WCE_DEL    CString Format(UINT nFormatID) const;
  1579. WCE_DEL    CString FormatGmt(UINT nFormatID) const;
  1580.  
  1581. #ifdef _UNICODE
  1582.     // for compatibility with MFC 3.x
  1583.     CString Format(LPCSTR pFormat) const;
  1584.     CString FormatGmt(LPCSTR pFormat) const;
  1585. #endif
  1586.  
  1587.     // serialization
  1588. #ifdef _DEBUG
  1589.     friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, CTime time);
  1590. #endif
  1591.     friend CArchive& AFXAPI operator<<(CArchive& ar, CTime time);
  1592.     friend CArchive& AFXAPI operator>>(CArchive& ar, CTime& rtime);
  1593.  
  1594. private:
  1595.     time_t m_time;
  1596. WCE_INS    friend class COleDateTime; // we want access to m_time
  1597. };
  1598.  
  1599. /////////////////////////////////////////////////////////////////////////////
  1600. // File status
  1601.  
  1602. struct CFileStatus
  1603. {
  1604.     CTime m_ctime;          // creation date/time of file
  1605.     CTime m_mtime;          // last modification date/time of file
  1606.     CTime m_atime;          // last access date/time of file
  1607.     LONG m_size;            // logical size of file in bytes
  1608.     BYTE m_attribute;       // logical OR of CFile::Attribute enum values
  1609.     BYTE _m_padding;        // pad the structure to a WORD
  1610.     TCHAR m_szFullName[_MAX_PATH]; // absolute path name
  1611.  
  1612. #ifdef _DEBUG
  1613.     void Dump(CDumpContext& dc) const;
  1614. #endif
  1615. };
  1616.  
  1617. /////////////////////////////////////////////////////////////////////////////
  1618. // Diagnostic memory management routines
  1619.  
  1620. // Low level sanity checks for memory blocks
  1621. BOOL AFXAPI AfxIsValidAddress(const void* lp,
  1622.             UINT nBytes, BOOL bReadWrite = TRUE);
  1623. BOOL AFXAPI AfxIsValidString(LPCWSTR lpsz, int nLength = -1);
  1624. BOOL AFXAPI AfxIsValidString(LPCSTR lpsz, int nLength = -1);
  1625.  
  1626. #if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
  1627.  
  1628. // Memory tracking allocation
  1629. void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
  1630. #define DEBUG_NEW new(THIS_FILE, __LINE__)
  1631. #if _MSC_VER >= 1200
  1632. void AFX_CDECL operator delete(void* p, LPCSTR lpszFileName, int nLine);
  1633. #endif
  1634.  
  1635. void* AFXAPI AfxAllocMemoryDebug(size_t nSize, BOOL bIsObject,
  1636.     LPCSTR lpszFileName, int nLine);
  1637. void AFXAPI AfxFreeMemoryDebug(void* pbData, BOOL bIsObject);
  1638.  
  1639. // Dump any memory leaks since program started
  1640. BOOL AFXAPI AfxDumpMemoryLeaks();
  1641.  
  1642. // Return TRUE if valid memory block of nBytes
  1643. BOOL AFXAPI AfxIsMemoryBlock(const void* p, UINT nBytes,
  1644.     LONG* plRequestNumber = NULL);
  1645.  
  1646. // Return TRUE if memory is sane or print out what is wrong
  1647. BOOL AFXAPI AfxCheckMemory();
  1648.  
  1649. #define afxMemDF _crtDbgFlag
  1650.  
  1651. enum AfxMemDF // memory debug/diagnostic flags
  1652. {
  1653.     allocMemDF          = 0x01,         // turn on debugging allocator
  1654.     delayFreeMemDF      = 0x02,         // delay freeing memory
  1655.     checkAlwaysMemDF    = 0x04          // AfxCheckMemory on every alloc/free
  1656. };
  1657.  
  1658. #ifdef _UNICODE
  1659. #define AfxOutputDebugString(lpsz) \
  1660.     do \
  1661.     { \
  1662.         USES_CONVERSION; \
  1663.         _RPT0(_CRT_WARN, W2CA(lpsz)); \
  1664.     } while (0)
  1665. #else
  1666. #define AfxOutputDebugString(lpsz) _RPT0(_CRT_WARN, lpsz)
  1667. #endif
  1668.  
  1669. // turn on/off tracking for a short while
  1670. BOOL AFXAPI AfxEnableMemoryTracking(BOOL bTrack);
  1671.  
  1672. // Advanced initialization: for overriding default diagnostics
  1673. BOOL AFXAPI AfxDiagnosticInit(void);
  1674.  
  1675. // A failure hook returns whether to permit allocation
  1676. typedef BOOL (AFXAPI* AFX_ALLOC_HOOK)(size_t nSize, BOOL bObject, LONG lRequestNumber);
  1677.  
  1678. // Set new hook, return old (never NULL)
  1679. AFX_ALLOC_HOOK AFXAPI AfxSetAllocHook(AFX_ALLOC_HOOK pfnAllocHook);
  1680.  
  1681. // Debugger hook on specified allocation request - Obsolete
  1682. void AFXAPI AfxSetAllocStop(LONG lRequestNumber);
  1683.  
  1684. // Memory state for snapshots/leak detection
  1685. struct CMemoryState
  1686. {
  1687. // Attributes
  1688.     enum blockUsage
  1689.     {
  1690.         freeBlock,    // memory not used
  1691.         objectBlock,  // contains a CObject derived class object
  1692.         bitBlock,     // contains ::operator new data
  1693.         crtBlock,
  1694.         ignoredBlock,
  1695.         nBlockUseMax  // total number of usages
  1696.     };
  1697.  
  1698.     _CrtMemState m_memState;
  1699.     LONG m_lCounts[nBlockUseMax];
  1700.     LONG m_lSizes[nBlockUseMax];
  1701.     LONG m_lHighWaterCount;
  1702.     LONG m_lTotalCount;
  1703.  
  1704.     CMemoryState();
  1705.  
  1706. // Operations
  1707.     void Checkpoint();  // fill with current state
  1708.     BOOL Difference(const CMemoryState& oldState,
  1709.                     const CMemoryState& newState);  // fill with difference
  1710.     void UpdateData();
  1711.  
  1712.     // Output to afxDump
  1713.     void DumpStatistics() const;
  1714.     void DumpAllObjectsSince() const;
  1715. };
  1716.  
  1717. // Enumerate allocated objects or runtime classes
  1718. void AFXAPI AfxDoForAllObjects(void (AFX_CDECL *pfn)(CObject* pObject, void* pContext),
  1719.     void* pContext);
  1720. void AFXAPI AfxDoForAllClasses(void (AFX_CDECL *pfn)(const CRuntimeClass* pClass,
  1721.     void* pContext), void* pContext);
  1722.  
  1723. #else
  1724.  
  1725. // non-_DEBUG_ALLOC version that assume everything is OK
  1726. #define DEBUG_NEW new
  1727. #define AfxCheckMemory() TRUE
  1728. #define AfxIsMemoryBlock(p, nBytes) TRUE
  1729. #define AfxEnableMemoryTracking(bTrack) FALSE
  1730. #define AfxOutputDebugString(lpsz) ::OutputDebugString(lpsz)
  1731.  
  1732. // diagnostic initialization
  1733. #ifndef _DEBUG
  1734. #define AfxDiagnosticInit() TRUE
  1735. #else
  1736. BOOL AFXAPI AfxDiagnosticInit(void);
  1737. #endif
  1738.  
  1739. #endif // _DEBUG
  1740.  
  1741. /////////////////////////////////////////////////////////////////////////////
  1742. // Archives for serializing CObject data
  1743.  
  1744. // needed for implementation
  1745. class CPtrArray;
  1746. class CMapPtrToPtr;
  1747. class CDocument;
  1748.  
  1749. class CArchive
  1750. {
  1751. public:
  1752. // Flag values
  1753.     enum Mode { store = 0, load = 1, bNoFlushOnDelete = 2, bNoByteSwap = 4 };
  1754.  
  1755.     CArchive(CFile* pFile, UINT nMode, int nBufSize = 4096, void* lpBuf = NULL);
  1756.     ~CArchive();
  1757.  
  1758. // Attributes
  1759.     BOOL IsLoading() const;
  1760.     BOOL IsStoring() const;
  1761.     BOOL IsByteSwapping() const;
  1762.     BOOL IsBufferEmpty() const;
  1763.  
  1764.     CFile* GetFile() const;
  1765.     UINT GetObjectSchema(); // only valid when reading a CObject*
  1766.     void SetObjectSchema(UINT nSchema);
  1767.  
  1768.     // pointer to document being serialized -- must set to serialize
  1769.     //  COleClientItems in a document!
  1770.     CDocument* m_pDocument;
  1771.  
  1772. // Operations
  1773.     UINT Read(void* lpBuf, UINT nMax);
  1774.     void Write(const void* lpBuf, UINT nMax);
  1775.     void Flush();
  1776.     void Close();
  1777.     void Abort();   // close and shutdown without exceptions
  1778.  
  1779.     // reading and writing strings
  1780.     void WriteString(LPCTSTR lpsz);
  1781.     LPTSTR ReadString(LPTSTR lpsz, UINT nMax);
  1782.     BOOL ReadString(CString& rString);
  1783.  
  1784. public:
  1785.     // Object I/O is pointer based to avoid added construction overhead.
  1786.     // Use the Serialize member function directly for embedded objects.
  1787.     friend CArchive& AFXAPI operator<<(CArchive& ar, const CObject* pOb);
  1788.  
  1789.     friend CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb);
  1790.     friend CArchive& AFXAPI operator>>(CArchive& ar, const CObject*& pOb);
  1791.  
  1792.     // insertion operations
  1793.     CArchive& operator<<(BYTE by);
  1794.     CArchive& operator<<(WORD w);
  1795.     CArchive& operator<<(LONG l);
  1796.     CArchive& operator<<(DWORD dw);
  1797.     CArchive& operator<<(float f);
  1798.     CArchive& operator<<(double d);
  1799.  
  1800.     CArchive& operator<<(int i);
  1801.     CArchive& operator<<(short w);
  1802.     CArchive& operator<<(char ch);
  1803.     CArchive& operator<<(unsigned u);
  1804.  
  1805.     // extraction operations
  1806.     CArchive& operator>>(BYTE& by);
  1807.     CArchive& operator>>(WORD& w);
  1808.     CArchive& operator>>(DWORD& dw);
  1809.     CArchive& operator>>(LONG& l);
  1810.     CArchive& operator>>(float& f);
  1811.     CArchive& operator>>(double& d);
  1812.  
  1813.     CArchive& operator>>(int& i);
  1814.     CArchive& operator>>(short& w);
  1815.     CArchive& operator>>(char& ch);
  1816.     CArchive& operator>>(unsigned& u);
  1817.  
  1818.     // object read/write
  1819.     CObject* ReadObject(const CRuntimeClass* pClass);
  1820.     void WriteObject(const CObject* pOb);
  1821.     // advanced object mapping (used for forced references)
  1822.     void MapObject(const CObject* pOb);
  1823.  
  1824.     // advanced versioning support
  1825.     void WriteClass(const CRuntimeClass* pClassRef);
  1826.     CRuntimeClass* ReadClass(const CRuntimeClass* pClassRefRequested = NULL,
  1827.         UINT* pSchema = NULL, DWORD* pObTag = NULL);
  1828.     void SerializeClass(const CRuntimeClass* pClassRef);
  1829.  
  1830.     // advanced operations (used when storing/loading many objects)
  1831.     void SetStoreParams(UINT nHashSize = 2053, UINT nBlockSize = 128);
  1832.     void SetLoadParams(UINT nGrowBy = 1024);
  1833.  
  1834. // Implementation
  1835. public:
  1836.     BOOL m_bForceFlat;  // for COleClientItem implementation (default TRUE)
  1837.     BOOL m_bDirectBuffer;   // TRUE if m_pFile supports direct buffering
  1838.     void FillBuffer(UINT nBytesNeeded);
  1839.     void CheckCount();  // throw exception if m_nMapCount is too large
  1840.  
  1841.     // special functions for reading and writing (16-bit compatible) counts
  1842.     DWORD ReadCount();
  1843.     void WriteCount(DWORD dwCount);
  1844.  
  1845.     // public for advanced use
  1846.     UINT m_nObjectSchema;
  1847.     CString m_strFileName;
  1848.  
  1849. protected:
  1850.     // archive objects cannot be copied or assigned
  1851.     CArchive(const CArchive& arSrc);
  1852.     void operator=(const CArchive& arSrc);
  1853.  
  1854.     BOOL m_nMode;
  1855.     BOOL m_bUserBuf;
  1856.     int m_nBufSize;
  1857.     CFile* m_pFile;
  1858.     BYTE* m_lpBufCur;
  1859.     BYTE* m_lpBufMax;
  1860.     BYTE* m_lpBufStart;
  1861.  
  1862.     // array/map for CObject* and CRuntimeClass* load/store
  1863.     UINT m_nMapCount;
  1864.     union
  1865.     {
  1866.         CPtrArray* m_pLoadArray;
  1867.         CMapPtrToPtr* m_pStoreMap;
  1868.     };
  1869.     // map to keep track of mismatched schemas
  1870.     CMapPtrToPtr* m_pSchemaMap;
  1871.  
  1872.     // advanced parameters (controls performance with large archives)
  1873.     UINT m_nGrowSize;
  1874.     UINT m_nHashSize;
  1875. };
  1876.  
  1877. /////////////////////////////////////////////////////////////////////////////
  1878. // Diagnostic dumping
  1879.  
  1880. // Note: AfxDumpStack is available in release builds, although it is always
  1881. //    statically linked so as to not negatively affect the size of MFC42.DLL.
  1882.  
  1883. #define AFX_STACK_DUMP_TARGET_TRACE            0x0001
  1884. #define AFX_STACK_DUMP_TARGET_CLIPBOARD    0x0002
  1885. #define AFX_STACK_DUMP_TARGET_BOTH            0x0003
  1886. #define AFX_STACK_DUMP_TARGET_ODS            0x0004
  1887. #ifdef _DEBUG
  1888. #define AFX_STACK_DUMP_TARGET_DEFAULT        AFX_STACK_DUMP_TARGET_TRACE
  1889. #else
  1890. #define AFX_STACK_DUMP_TARGET_DEFAULT        AFX_STACK_DUMP_TARGET_CLIPBOARD
  1891. #endif
  1892.  
  1893. void AFXAPI AfxDumpStack(DWORD dwFlags = AFX_STACK_DUMP_TARGET_DEFAULT);
  1894.  
  1895. class CDumpContext
  1896. {
  1897. public:
  1898.     CDumpContext(CFile* pFile = NULL);
  1899.  
  1900. // Attributes
  1901.     int GetDepth() const;      // 0 => this object, 1 => children objects
  1902.     void SetDepth(int nNewDepth);
  1903.  
  1904. // Operations
  1905.     CDumpContext& operator<<(LPCTSTR lpsz);
  1906. #ifdef _UNICODE
  1907.     CDumpContext& operator<<(LPCSTR lpsz);  // automatically widened
  1908. #else
  1909.     CDumpContext& operator<<(LPCWSTR lpsz); // automatically thinned
  1910. #endif
  1911.     CDumpContext& operator<<(const void* lp);
  1912.     CDumpContext& operator<<(const CObject* pOb);
  1913.     CDumpContext& operator<<(const CObject& ob);
  1914.     CDumpContext& operator<<(BYTE by);
  1915.     CDumpContext& operator<<(WORD w);
  1916.     CDumpContext& operator<<(UINT u);
  1917.     CDumpContext& operator<<(LONG l);
  1918.     CDumpContext& operator<<(DWORD dw);
  1919.     CDumpContext& operator<<(float f);
  1920.     CDumpContext& operator<<(double d);
  1921.     CDumpContext& operator<<(int n);
  1922.     void HexDump(LPCTSTR lpszLine, BYTE* pby, int nBytes, int nWidth);
  1923.     void Flush();
  1924.  
  1925. // Implementation
  1926. protected:
  1927.     // dump context objects cannot be copied or assigned
  1928.     CDumpContext(const CDumpContext& dcSrc);
  1929.     void operator=(const CDumpContext& dcSrc);
  1930.     void OutputString(LPCTSTR lpsz);
  1931.  
  1932.     int m_nDepth;
  1933.  
  1934. public:
  1935.     CFile* m_pFile;
  1936. };
  1937.  
  1938. #ifdef _DEBUG
  1939. extern AFX_DATA CDumpContext afxDump;
  1940. extern AFX_DATA BOOL afxTraceEnabled;
  1941. #endif
  1942.  
  1943. /////////////////////////////////////////////////////////////////////////////
  1944. // Special include for Win32s compatibility
  1945.  
  1946. #ifdef _AFX_PACKING
  1947. #pragma pack(pop)
  1948. #endif
  1949.  
  1950. #ifndef __AFXCOLL_H__
  1951.     #include <afxcoll.h>
  1952.     #ifndef __AFXSTATE_H__
  1953.         #include <afxstat_.h> // for _AFX_APP_STATE and _AFX_THREAD_STATE
  1954.     #endif
  1955. #endif
  1956. #if defined(_WIN32_WCE) 
  1957. // WinCE: Windows CE Database API support
  1958. #include "wcedb.h"
  1959. #endif // _WIN32_WCE
  1960.  
  1961. /////////////////////////////////////////////////////////////////////////////
  1962. // Inline function declarations
  1963.  
  1964. #ifdef _AFX_ENABLE_INLINES
  1965. #define _AFX_INLINE AFX_INLINE
  1966.  
  1967. #if !defined(_AFX_CORE_IMPL) || !defined(_AFXDLL) || defined(_DEBUG)
  1968. #define _AFX_PUBLIC_INLINE AFX_INLINE
  1969. #else
  1970. #define _AFX_PUBLIC_INLINE
  1971. #endif
  1972.  
  1973. #include <afx.inl>
  1974. #endif
  1975.  
  1976. #undef AFX_DATA
  1977. #define AFX_DATA
  1978.  
  1979. #ifdef _AFX_MINREBUILD
  1980. #pragma component(minrebuild, on)
  1981. #endif
  1982. #ifndef _AFX_FULLTYPEINFO
  1983. #pragma component(mintypeinfo, off)
  1984. #endif
  1985.  
  1986. #endif // __AFX_H__
  1987.  
  1988. /////////////////////////////////////////////////////////////////////////////
  1989.